import 'package:flutter/material.dart';
import 'package:yp/config/index.dart';
import 'package:yp/config/style.dart';
import 'package:yp/widgets/index.dart';

/// 退货进度
class RefundProgress extends StatefulWidget {
  const RefundProgress({Key key}) : super(key: key);

  @override
  _RefundProgressState createState() => _RefundProgressState();
}

class _RefundProgressState extends State<RefundProgress>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  /// 1退款进度 需要寄回 2退款进度 无需寄回  3退款进度 审核失败
  int _pageType = 3;

  Map<int, List> _progressMap = {
    1: [
      {'text': '退款成功，已退款至微信账户', 'time': '07-21 10:10', 'selected': true},
      {'text': '商家已收货，并发起退款', 'time': '07-21 10:10', 'selected': false},
      {'text': '退货已寄回，待商家收货', 'time': '07-21 10:10', 'selected': false},
      {'text': '审核成功，退货商品待寄回', 'time': '07-21 10:10', 'selected': false},
      {'text': '已经提交退货申请，待商家审核', 'time': '07-21 10:10', 'selected': false}
    ],
    2: [
      {'text': '退款成功，已退款至微信账户', 'time': '07-21 10:10', 'selected': true},
      {'text': '发起退款申请', 'time': '07-21 10:10', 'selected': false},
      {'text': '审核成功，退货商品无需寄回', 'time': '07-21 10:10', 'selected': false},
      {'text': '已经提交退货申请，待商家审核', 'time': '07-21 10:10', 'selected': false}
    ],
    3: [
      {
        'text': '审核失败',
        'msg':
            '不好意思，不是我们不想给你退，关键你这都已经拆开并使用了，所以不能再退了。不好意思，不是我们不想给你退，关键你这都已经拆开并使用了，所以不能再退了。不好意思，不是我们不想给你退，关键你这都已经拆开并使用了，所以不能再退了。不好意思，不是我们不想给你退，关键你这都已经拆开并使用了，所以不能再退了。不好意思，不是我们不想给你退，关键你这都已经拆开并使用了，所以不能再退了。',
        'time': '07-21 10:10',
        'selected': false
      },
      {'text': '已经提交退货申请，待商家审核', 'time': '07-21 10:10', 'selected': false}
    ]
  };

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: YPNavigationBar( '退货进度'),
      body: _body(),
    );
  }

  Widget _body() {
    return ListView.builder(
        itemCount: _progressMap[_pageType]?.length ?? 0,
        itemBuilder: (context, index) {
          return _progress(
              _progressMap[_pageType][index]['selected'],
              _progressMap[_pageType][index]['text'],
              _progressMap[_pageType][index]['time'],
              top: index == 0,
              end: index == (_progressMap[_pageType]?.length ?? 0) - 1,
              msg: _progressMap[_pageType][index]['msg'] ?? '');
        });
  }

  Widget _progress(bool selected, String text, String time,
      {bool top = false, bool end = false, String msg = ''}) {
    return IntrinsicHeight(
      child: Container(
        color: EsColors.White,
        padding: EdgeInsets.symmetric(horizontal: 12),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  color: top ? Colors.transparent : EsColors.BackGround,
                  width: 1,
                  height: 20,
                ),
                Icon(
                  Icons.radio_button_checked,
                  color: (msg?.isNotEmpty ?? false)
                      ? EsColors.Pink
                      : (selected ? Colors.green : EsColors.BackGround),
                ),
                Expanded(
                  child: Container(
                    color: end ? Colors.transparent : EsColors.BackGround,
                    width: 1,
                  ),
                )
              ],
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(top: 20, left: 8),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Expanded(
                            child: Text(
                          text ?? '',
                          style: TextStyle(
                              color: selected
                                  ? EsColors.TitleSecondary
                                  : EsColors.Content,
                              fontSize: EsSizes.SM,
                              fontWeight: EsFontWeights.Normal),
                        )),
                        Text(
                          time ?? '',
                          style: TextStyle(
                              color: EsColors.Content,
                              fontSize: EsSizes.XS,
                              fontWeight: EsFontWeights.Normal),
                        )
                      ],
                    ),
                    Visibility(
                      visible: msg?.isNotEmpty ?? false,
                      child: Text(
                        '失败原因$msg',
                        style: TextStyle(
                            color: EsColors.ContentSecondary,
                            fontSize: EsSizes.XS,
                            fontWeight: EsFontWeights.Normal),
                      ),
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

}
